from rest_framework.decorators import action
from rest_framework.generics import ListAPIView,RetrieveAPIView
from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response


from goods.models import SPU, Brand, GoodsCategory
from meiduo_admin.serializers.goods import SPUSerializer, BrandSimpleSerializer, CategoriesSimpleSerializer,SimpleSerializer


class SPUViewSet(ModelViewSet):
    """SPU商品详情视图集"""
    permission_classes = [IsAdminUser]

    serializer_class = SPUSerializer

    queryset = SPU.objects.all()

    def Simple(self,request):
        """品牌简单展示"""
        queryset = Brand.objects.all()

        serializer = BrandSimpleSerializer(queryset, many=True)

        return Response(serializer.data)


class CategoriesView(ListAPIView):
    """一级分类简单展示"""
    permission_classes = [IsAdminUser]
    queryset = GoodsCategory.objects.filter(parent=None)

    serializer_class = CategoriesSimpleSerializer
    pagination_class = None


class CategoryView(RetrieveAPIView):
    """一级分类简单展示"""
    permission_classes = [IsAdminUser]
    queryset = GoodsCategory.objects.all()
    serializer_class = SimpleSerializer
    # pagination_class = None
